package com.ggh.jinjilive.dialog;

import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;

import com.blankj.utilcode.util.KeyboardUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.cy.dialog.BaseDialog;
import com.ggh.jinjilive.R;
import com.ggh.jinjilive.listener.AddOnClickListener;


/**
 * 发送消息
 */
public class LiveSendMessageDialog extends BaseDialog {
    private EditText et_content;
    //弹
    private ImageView ib_play;
    //弹
    public boolean play = false;

    public LiveSendMessageDialog(Context context) {
        super(context);
    }

    public LiveSendMessageDialog(Context context, int themeResId) {
        super(context, themeResId);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        contentView(R.layout.dialog_live_message);
        getWindow().setDimAmount(0f);
        canceledOnTouchOutside(true);
        animType(AnimInType.BOTTOM);
        gravity(Gravity.BOTTOM);
        //弹
        ib_play = findViewById(R.id.ib_play);
        if(play){
            ib_play.setImageResource(R.mipmap.barrage_slider_on);
        }else {
            ib_play.setImageResource(R.mipmap.barrage_slider_off);
        }
        ib_play.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(play){
                    play = false;
                    ib_play.setImageResource(R.mipmap.barrage_slider_off);
                }else {
                    play = true;
                    ib_play.setImageResource(R.mipmap.barrage_slider_on);
                }
            }
        });
        //内容
        et_content = findViewById(R.id.et_content);
        et_content.setFocusable(true);
        et_content.setFocusableInTouchMode(true);
        et_content.requestFocus();
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        //发送
        findViewById(R.id.tv_send).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //内容
                String content = et_content.getText().toString();
                if(TextUtils.isEmpty(content)){
                    ToastUtils.make().show("请输入内容");
                    return;
                }
                if(null != addOnClickListener){
                    KeyboardUtils.hideSoftInput(v);
                    addOnClickListener.onSkipClicked(content);
                    et_content.setText("");
                }
            }
        });

    }


    private AddOnClickListener addOnClickListener;
    public void setAddOnClickListener(AddOnClickListener addOnClickListener){
        this.addOnClickListener = addOnClickListener;
    }


    /**
     * @消息
     * @param etContent
     */
    public void etContent(String etContent){
        if(null == et_content){
            et_content = findViewById(R.id.et_content);
        }
        et_content.setText(etContent);
    }


    @Override
    public void show() {
        super.show();
        Window window = getWindow();
        //设置弹出位置
        window.setGravity(Gravity.BOTTOM);
        //设置对话框大小
        window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    }
}
